package com.metagurukul.informer.service;

import java.sql.SQLException;
import com.metagurukul.informer.dao.ForgotPasswordDAO;
import com.metagurukul.informer.dao.LoginUserDAO;

public class ForgotPasswordService {
	
	private String emailId="";
	ForgotPasswordDAO forgotPasswordDao;
	LoginUserDAO loginuserdao;
	public ForgotPasswordService(String emailId) {
		this.emailId=emailId;
	}
	/**
	 * check that if user is a member or not
	 * @return true if exist else false
	 * @throws SQLException
	 */
	public boolean isUserExist() throws SQLException{
		loginuserdao=new LoginUserDAO();
		boolean isExist=false;
		try {
			isExist=loginuserdao.isExistingUser(emailId);
		} catch (Exception e) {
			throw new SQLException();
		}
		
		return  isExist;
	}
	/**
	 * 
	 * @return the password of requested user
	 * @throws SQLException
	 */
	public String getPassword() throws SQLException{
	
		forgotPasswordDao=new ForgotPasswordDAO();
		if(forgotPasswordDao.getPassword(emailId)==null){
			throw new NullPointerException();
		}else{
			return forgotPasswordDao.getPassword(emailId);
		}
		
	}
}
